package com.fancy.ui
{
	import com.fancy.framework.BundleContext;
	import com.fancy.framework.BundleLeader;
	import com.fancy.framework.BundleModuleName;
	import com.fancy.framework.BundleNotice;
	import com.fancy.ui.notice.UIKeyNotice;
	import com.fancy.ui.notice.UINoticeType;
	
	public class UILeader extends BundleLeader
	{
		
		public function UILeader(context:BundleContext)
		{
			super(context);
		}
		
		override public function getModuleName():String
		{
			return BundleModuleName.USER_INTERFACE;
		}
		
		override public function getLevel():uint
		{
			return 2;
		}
		
		override public function initializeLeader():void
		{
			trace("UILeader::initializeLeader()");
			MainManage.initialize();
		}
		
		override public function execute(notice:BundleNotice):void
		{
			trace("UILeader::execute ", notice.type, notice.name, notice.body);
			switch(notice.type)
			{
			case UINoticeType.KEY_EVENT:
				keyNoticeHandler(notice);
				break;
			case UINoticeType.GAME_LOGIC:
				logicNoticeHandler(notice);
				break;
			case UINoticeType.SRV_MSG:
				srvNoticeHandler(notice);
				break;
			}
		}
		
		private function keyNoticeHandler(notice:BundleNotice):void
		{
			switch(notice.name)
			{
			case UIKeyNotice.SOCKET_CROSS_DOMAIN_OK:
				MainManage.loginManage.handleConnect(0);
				break;
			case UIKeyNotice.SOCKET_CONNECTED:
				MainManage.loginManage.handleConnect(1);
				break; 
			case UIKeyNotice.SOCKET_CONNECT_ERROR:
				MainManage.loginManage.handleConnect(2);
				break;
			case UIKeyNotice.SOCKET_CLOSE:
				MainManage.loginManage.handleConnect(3);
				break;
			}
		}
		
		private function logicNoticeHandler(notice:BundleNotice):void
		{
			
		}
		
		private function srvNoticeHandler(notice:BundleNotice):void
		{
			
		}
		
	}
}